import {
	Jump
} from '@/libs/fn/jump.js'
import store from '../store/index.js'
import {
	getAppVersion,
	chechVersion
} from './upgrade.js'
import {
	pathToBase64,
	base64ToPath
} from 'image-tools'

/**
 * @function 小数转大数 
 * @description 将给定资金转换为以wei为单位的数值  类似  web3.toWei 方法
 * @param {Number} num    被操作数
 * @param {Number} digit  位数
 * @returns 
 * @example 
 */
const toWei = (num, digit = 0) => {
	if (!num || num <= 0) return 0;
	if (digit <= 0) return num;
	let strNum = num.toString().split(".");
	if (strNum.length == 1) {
		return strNum[0] + "" + digitNum(digit);
	} else {
		strNum = strNum[0] + strNum[1] + digitNum(digit - strNum[1].length);
	}
	return strNum;
}

/**
 * @function 大数转小数 
 * @description 以太坊货币单位之间的转换。将以wei为单位的资金，转换为指定单位的数值 类似  web3.fromWei 方法
 * @param {Number} num    被操作数
 * @param {Number} digit  位数
 * @returns 
 * @example 
 */
const fromWei = (num, digit = 0) => {
	if (!num || num <= 0) return 0;
	if (digit <= 0) return num;
	let strNum = num.toString();
	let length = strNum.length;
	if (strNum.indexOf(".") == -1) {
		//返回值没有小数点
		if (length <= digit) {
			strNum = "0." + digitNum(digit - length) + "" + strNum;
		} else {
			strNum = strNum.substring(0, strNum.length - digit) + "." + strNum.slice(strNum.length - digit);
		}
	} else { //返回值小于位数的情况 即有小数点
		let a = strNum.split('.')[0];
		let b = strNum.split('.')[1];
		if (a.length <= digit) {
			strNum = "0." + digitNum(digit - a.length) + '' + a + b;
		} else {
			strNum = a.substring(0, a.length - digit) + "." + a.slice(a.length - digit) + b;
		}
	}
	return handleCutZero(strNum);
}

/**
 * @name: handleCutZero
 * @description:  去掉double类型小数点后面多余的0参数：old 要处理的字符串或double返回值：newStr 没有多余零的小数或字符串
 * @param {*} num
 * @return {*}num
 */
function handleCutZero(num) {
	//拷贝一份 返回去掉零的新串
	let newstr = num;
	//循环变量 小数部分长度
	let leng = num.length - num.indexOf('.') - 1;
	//判断是否有效数
	if (num.indexOf('.') > -1) {
		//循环小数部分
		for (let i = leng; i > 0; i--) {
			//如果newstr末尾有0
			if (
				newstr.lastIndexOf('0') > -1 &&
				newstr.substr(newstr.length - 1, 1) == 0
			) {
				let k = newstr.lastIndexOf('0');
				//如果小数点后只有一个0 去掉小数点
				if (newstr.charAt(k - 1) == '.') {
					return newstr.substring(0, k - 1);
				} else {
					//否则 去掉一个0
					newstr = newstr.substring(0, k);
				}
			} else {
				//如果末尾没有0
				return newstr;
			}
		}
	}
	return num;
}

function digitNum(digit) {
	let a = "";
	for (let i = 0; i < digit; i++) {
		a += "0";
	}
	return a;
}

const getConfig = (v) => {
	console.log('store', store.state.general.config)
	return store.state.general.config[v]
}

const Toast = (content) => {
	// #ifdef APP-PLUS
	return plus.nativeUI.toast(content);
	// #endif
	// #ifdef H5
	return uni.showToast({
		title: content,
		duration: 1500,
		icon: 'none',
		position: 'bottom',
	})
	// #endif
}

// 复制
const doCopy = (data, toast = true) => {
	return new Promise((resolve, reject) => {
		try {
			uni.setClipboardData({
				data: data.toString(),
				success: function() {
					uni.showToast({
						icon: 'none',
						title: '复制成功'
					});
					if (!toast) {
						uni.hideToast()
					}
					resolve(true)
				},
				fail(e) {
					uni.showToast({
						icon: 'none',
						title: '复制失败'
					});
					reject(false)
				}
			});
		} catch (e) {}
	})
}


//验证指纹
const isFingerprint = () => {
	let a = 'error'
	// #ifdef APP-PLUS
	if (!plus.fingerprint.isSupport()) {
		a = 'error' //没有指纹功能 
	} else if (!plus.fingerprint.isKeyguardSecure()) {
		a = 'fall'
	} else if (!plus.fingerprint.isEnrolledFingerprints()) {
		a = 'fall'
	} else {
		a = 'success'
	}
	// #endif
	if (a !== 'success') {
		store.commit('setting/SET_ISFINGER', false)
	}
	store.commit('setting/SET_FINGERPRINT', a)
}

const isNetwork = () => {
	uni.getNetworkType({
		success: ({
			networkType
		}) => {
			if (networkType == 'none') {
				Jump({
					url: '/pages/error',
					mode: 4,
					params: {
						msg: '无网络'
					}
				})
			}
			if (networkType == '2g' || networkType == '3g') {
				Toast('当前网络较慢')
			}
		}
	});
}
const onNetwork = () => {
	uni.onNetworkStatusChange(({
		isConnected,
		networkType
	}) => {
		store.commit('setting/SET_NETWORK', isConnected)
		if (networkType == 'none') {
			Jump({
				url: '/pages/error',
				mode: 4,
				params: {
					msg: '无网络'
				}
			})
		}
		if (networkType == '2g' || networkType == '3g') {
			Toast('当前网络较慢')
		}
	})

}

//获取UUID
const getUUID = () => {
	try {
		//#ifdef APP
		return new Promise((resolve, reject) => {
			plus.device.getInfo({
				success: function({
					uuid
				}) {
					resolve(uuid)
					console.log(e);
				},
				fail: function(e) {
					console.log('failed: ' + e);
					resolve(false)
				}
			});
		})
		//#endif
		return
	} catch (e) {
		return
		//TODO handle the exception
	}
}



const imgToBase64 = (data) => {
	return new Promise((resolve, reject) => {
		pathToBase64(data).then(base64 => {
			resolve(base64)
		}).catch(error => {
			console.error(error)
			reject(error)
		})
	})
}


//指纹识别
const fingerprint = () => {
	return new Promise((resolve, reject) => {
		try {
			// #ifdef APP-PLUS
			uni.startSoterAuthentication({
				requestAuthModes: ['fingerPrint'],
				challenge: '123456',
				success(res) {
					resolve(true)
				},
				fail(err) {
					resolve(false)
				},
			})
			// #endif

		} catch (e) {
			resolve(false)
		}

	})
}

//扫码
const doScanCode = () => {
	return new Promise((resolve, reject) => {
		uni.scanCode({
			scanType: ['qrCode'],
			success: function({
				result
			}) {
				resolve(result)
			},
			fail() {
				resolve(false)
			}
		});
	})
}

// 截取指定字符前/后的字符 不包含指定字符（obj：原字符串；character：指定字符；state：0前面部分1后面部分）
const getCaption = (obj, character, state) => {
	var index = obj.indexOf(character);
	if (state == 0) {
		obj = obj.substring(0, index);
	} else {
		obj = obj.substring(index + character.length, obj.length);
	}
	return obj;
}

// 截取指定字符前/后的字符 包含指定字符（obj：原字符串；character：指定字符；state：0前面部分1后面部分）
const getCaption1 = (obj, character, state) => {
	var index = obj.indexOf(character);
	if (state == 0) {
		obj = obj.substring(0, index + character.length);
	} else {
		obj = obj.substring(index, obj.length);
	}
	return obj;
}

// 获取地址中的省市区
const getProvinces = (poiaddress) => {
	let provinces = {};
	let reg = /.+?(省|市|自治区|自治州|县|区)/g;
	let ssqList = poiaddress.match(reg);
	ssqList.map((item, index) => {
		switch (index) {
			case 0: // 省、自治区、直辖市、特别行政区
				provinces.province = item;
				break;
			case 1: // 地级市、地区、自治州、盟
				if (provinces.province.lastIndexOf("省") != -1 || provinces.province.lastIndexOf("自治区") != -
					1) {
					provinces.city = item;
				} else if (provinces.province.lastIndexOf("市") != -1) {
					provinces.county = item;
					provinces.city = "市辖区"; // location.province
				} else {
					provinces.county = item;
				}
				break;
			case 2: // 市辖区、县级市、县、自治县、旗、自治旗、特区、林区
				if (provinces.province.lastIndexOf("省") != -1 || provinces.province.lastIndexOf("自治区") != -
					1) {
					provinces.county = item;
				}
				break;
			default:
				break;
		}

	});
	return provinces;
}

// 获取定位信息
const getLocation = () => {
	let location = {};
	uni.getLocation({
		type: 'wgs84',
		geocode: true, //设置该参数为true可直接获取经纬度及城市信息
		success: function(res) {
			console.log('获取定位信息', res);
			location.latitude = res.latitude;
			location.longitude = res.longitude;
			//#ifdef APP-PLUS
			location.area = res.address.city;
			//#endif

			//#ifdef H5

			//#endif

			console.log('定位信息', location);
			store.commit("location/SET_LOCATIONINFO", location);
		},
		fail: function(err) {
			console.log("获取定位失败", err);
			uni.showToast({
				title: '获取地址失败，将导致部分功能不可用',
				icon: 'none'
			});
		}
	});

}

// 打开链接或页面
const JumpUrl = async (url, type = 1) => {
	if (!url && type == 1) return Toast('系统升级中');
	let reg = new RegExp('http')
	// url不包含http 跳转页面
	if (!reg.test(url)) return Jump(url);
	// 跳转链接
	openURL({
		openUrl: url
	});
}
// 跳转外部浏览器 
// openUrl----  链接地址
// openType---  webview 内部浏览器  browser 外部浏览器  
// isToast---   是否提示 
const openURL = async ({
	openUrl,
	openType = 'webview',
	isToast = false,
	type = 'url'
} = {}) => {
	if (!openUrl) return Toast('即将上线');
	// url要用trim()去除两端空格，否则在Android平台打开会报错
	// #ifdef APP-PLUS
	// url 是链接地址 不可访问
	if (type == 'apk' && !await urlIsOK(openUrl)) return Toast('打包升级中...');
	if (isToast) {
		let res = await uni.showModal({
			title: '打开链接?',
			content: '即将打开链接：' + openUrl,
		});
		const {
			confirm,
			cancel
		} = res[0] || res[1];
		if (cancel) {
			return false;
		}
	}
	// webview打开
	if (openType == 'webview') {
		uni.navigateTo({
			url: '/pages/webview/webview?url=' + openUrl
		})
	}
	// 外部浏览器打开
	if (openType != 'webview') {
		plus.runtime.openURL(openUrl, err => {
			console.log("打开失败===>", err)
			if (plus.os.name == "Android") {
				plus.runtime.launchApplication({
					pname: "com.android.browser",
					extra: {
						url: openUrl
					}
				}, function(e) {
					console.log(e);
				});
			} else if (plus.os.name == "iOS") {
				plus.runtime.launchApplication({
					action: openUrl
				}, function(e) {
					console.log(e);
				});
			}
		});
	}
	// #endif
	// #ifndef APP-PLUS
	window.open(openUrl)
	// #endif

}
const urlIsOK = async (url, param = {}) => {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url,
			data: param,
			method: "GET",
			success: function(res) {
				if (res.statusCode !== 200) {
					resolve(true);
				} else {
					resolve(true);
				}
			},
			fail: function(err) {
				resolve(false);
			}
		})
	})
}


/**
 * @function 间隔时间time(s)
 * @param {Number} time 秒
 * @returns 
 */
const sleep = (time) => {
	return new Promise(resolve => {
		setTimeout(() => {
			console.log(`执行等待${time}s---`);
			resolve();
		}, time * 1000);
	});
}

const guid = () => {
	function S4() {
		return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
	}
	return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}


/**
 * 首页公告第一条弹框
 * @param idx    // 公告idx
 * @returns boolean      （true|| false）
 */

const openNotice = (idx) => {
	if (!uni.getStorageSync('newsidx')) {
		uni.setStorageSync('newsidx', idx);
		return true;
	} else {
		if (uni.getStorageSync('newsidx') == idx) return false
		uni.setStorageSync('newsidx', idx);
		return true
	}
}

// 支付调转链接
const payJump = (data, payType) => {
	const system = uni.getSystemInfoSync()
	console.log('system===>', system)
	// console.log(res.data);
	// const meth = {
	// 	"PaymentWayNo3":this.balancePayment(data),
	// 	"PaymentWayNo3":this.balancePayment(data),
	// }
	switch (payType) {
		//微信支付---火链支付
		case "11":
			// #ifdef APP-PLUS
			///app微信；拉起小程序支付
			const {
				openlink
			} = JSON.parse(data)
			openURL({
				openUrl: openlink,
				openType: ' '
			})
			// Jump('/pages/webview/webview?title=微信收银台&url=' + openlink)
			// plus.share.getServices(function(res) {
			// 	let sweixin = null;
			// 	for (let i = 0; i < res.length; i++) {
			// 		let t = res[i];
			// 		if (t.id == 'weixin') {
			// 			sweixin = t;
			// 		}
			// 	}
			// 	if (sweixin) {
			// 		// { 
			// 		// 	"order_no": "P542139103454493965", 
			// 		// 	"trx_no": "100223030859193698", 
			// 		// 	"payee_name": "大富购电子商务", 
			// 		// 	"original_id": "gh_030d020d002f", 
			// 		// 	"app_id": "d3g2NmE5ZWEwY2VkZjc5ZjMx", 
			// 		// 	"product_name": "大富购电子商务云南有限公司", 
			// 		// 	"order_amout": 58,
			// 		// }
			// 		sweixin.launchMiniProgram({
			// 			id: 'gh_030d020d002f',
			// 			type: 0,
			// 			path: '/pages/payIndex/payIndex?rc_result=' + data
			// 		});
			// 	}
			// }, (res) => {
			// 	console.log(JSON.stringify(res));
			// });
			// #endif
			// #ifdef H5
			// 微信H5支付  直接跳转webview
			const {
				openlink
			} = JSON.parse(data)
			window.location.href = openlink;
			// if (system.platform == 'ios') {
			// 	//如果是iOS平台(window.open在ios平台会被拦截)
			// } else {
			// 	window.location.href = openlink
			// 	// Jump('/pages/webview/webview?title=微信收银台&url=' + openlink)
			// }
			// #endif
			break;
		case '32':
			Jump('/pages/webview/webview?title=微信扫码支付&code=' + data)
			break;
		case '22':
		case '31':
		case '34':
		case '33':
		case '23': // 杉德支付
			// #ifdef APP-PLUS
			openURL({
				openUrl: data,
				openType: ' '
			})
			// #endif
			// #ifdef H5
			window.location.href = data
			break;
			// #endif
		case "12": // 支付宝---火链支付
			// #ifdef APP-PLUS
			// /支付宝APP支付跳转webview
			openURL({
				openUrl: data,
				openType: ' '
			})
			// Jump('/pages/webview/webview?title=支付宝收银台&url=' + data)
			// #endif
			// #ifdef H5
			window.location.href = data
			// #endif
			// if (system.platform == 'ios') {
			// 	window.location.href = data
			// } else {

			// }
			break;
			// 支付宝---官方通道
		case "3":
			// #ifdef APP-PLUS
			// /支付宝APP支付跳转webview
			Jump('/pages/webview/webview?title=支付宝收银台&url=' + data)
			// #endif
			// #ifdef H5
			window.location.href = data
			// #endif
			break;
		default:
			return false
	}
}

//对象清除null或''属性
const removeProperty = (obj) => {
	if (!obj) return {};
	Object.keys(obj).forEach(item => {
		if (obj[item] === '' || obj[item] === undefined || obj[item] === null || obj[item] === 'null' ||
			obj[item] === {})
			delete obj[item]
	})
	return obj
}

// 对象 根据key 返回新的对象
const getNewObjByKeyArr = () => {

}

// 对象 过滤多个key
const objDelKeyArr = (obj, key) => {
	for (i in obj) {
		console.log(i)
		if (i == key) {
			delete obj[i] //使用delete关键字会将属性完全删除，遍历不会在出现属性名
			// obj[i] = undefined //使用undefined只是将值去除但是遍历还是会出现属性名
		}
		while (typeof(obj[i]) == "object") {
			del(obj[i], key)
		}

	}
	i = null //每次循环后重置null复制可能会发生i的值相同造成的死循环
	return obj
}
/**
 * 数组对象---组合两个key的value 为新的枚举 
 * @param {object} arrObj 
 * @param {String} key1 
 * @param {String} key2 
 * @example 
   let arrObj=[{name:'充值',tradeType:1},{name:'兑换',tradeType:2}]
   arrObjGetEnum(arrObj,'tradeType','name') =======> {1:'充值',2:'兑换'}
 */
const arrObjGetEnum = (arrObj, key1, key2) => {
	let b = {};
	arrObj.forEach(item => {
		b[item[key1]] = item[key2];
	})
	return b;
}

/**
 * @description: 数组对象--通过 key值去重
 * @param {Array} arr 要去重的数组
 * @param {String} uniqueKey 唯一标识
 * @return: arr 去重后的数组
 */
const arrObjremovalRepeat = (arr, uniqueKey) => {
	let map = new Map();
	for (let i of arr) {
		if (!map.has(i[uniqueKey])) {
			map.set(i[uniqueKey], i);
		}
	}
	arr = [...map.values()];
	return arr;
}

/**
 * @description: 数组对象--通过 一个key值返回数组
 * @param {Array} arr 数组对象
 * @param {String} onekey key
 * @return: arr 数组
 */
const arrObjGetArrByOneKey = (arrObj, oneKey, type = null) => {
	let b = [];
	arrObj.forEach(item => {
		if (type == 'string') {
			b.push(item[oneKey].toString())
		} else {
			b.push(item[oneKey])
		}

	})
	return b;
}

/**
 * @description: 枚举转数组--通过 一个key值返回数组
 * @param {String} key1 key
 * @param {String} key2 key
 * @return: arr 数组
 * @example 
           let enumObj={0:"全部",1:"充值",11:"直推奖励"}
           enumObjToArr(enumObj,'id','name') =======> [{id:0,name:'全部'}{id:1,name:'充值'{id:11,name:'直推奖励'}}]
 */
const enumObjToArr = (enumObj, key1, key2) => {
	let arr = Object.keys(enumObj).map(function(i) {
		const c = {};
		c[key1] = i, c[key2] = enumObj[i];
		return c;
	});
	return arr;
	// let b = [];
	// for (var prop in enumObj) {
	// 	const c={};
	// 	c[key1] = prop;
	// 	c[key2] = enumObj[prop];
	// 	b.push(c)
	// }
	// return b
}

const chooseImage = async () => {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: 1, //默认9
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: type == 1 ? ['camera'] : ['album'], //从相册选择
			success: function({
				tempFilePaths,
				tempFiles
			}) {
				tempFiles[0].FileName = tempFiles[0]['name'];
				resolve(tempFilePaths)
			}
		});
	})
}
/**
 * @desc 根据对象数组中的指定属性进行数组元素排序
 * @param objArr 要进行排序操作的对象数组
 * @param attribute 排序属性
 * @param orderFlag 方式标识,true 为正序 false 为倒序 默认为 true
 * @returns 完成排序后的数组
 */
const objectArraySortByAtr = (objArr, attribute, orderFlag = true) => {
	function compare(key, sortFlag) {
		let sortFlagRes;
		if (sortFlag) {
			sortFlagRes = 1;
		} else {
			sortFlagRes = sortFlag ? 1 : -1;
		}
		return function(value1, value2) {
			const val1 = value1[key];
			const val2 = value2[key];
			if (val1 < val2) {
				return sortFlagRes * -1;
			}
			if (val1 > val2) {
				return sortFlagRes * 1;
			}
			return 0;
		};
	}
	return objArr.sort(compare(`${attribute}`, orderFlag));
}
/**
 * @desc 判断是否处于本周
 * @param param  为时间戳（默认） 日期时间字符串，
 * @param type  为timestamp  datetime
 示例：
 weekJudge(1669961510000)
 weekJudge(‘2023-04-16 21:45:00’, ‘datetime’)
 */
const weekJudge = (param, type = 'timestamp') => {
	// 如果传入的时间戳是字符串，需要进行类型转换
	if ((typeof param === 'string') && type == 'timestamp') {
		param = Number(param)
	}
	if (type == 'datetime') { // ios日期时间兼容
		param = param.replace(/-/g, "/")
	}
	var paramStamp = new Date(param).setHours(0, 0, 0, 0) // 传入的时间戳，将时间部分转换为0
	var currentDate = new Date() // 当天
	var currentStamp = currentDate.setHours(0, 0, 0, 0) // 当天日期，转换为时间部分为0的时间戳
	var currentDay = currentDate.getDay() == 0 ? 7 : currentDate.getDay() // 当天周几，取值为（0-6），0为周日，转换为7
	console.log('当前周：', currentDay, currentDate)
	var dayTime = 24 * 60 * 60 * 1000 // 一天的毫秒数
	var MondayStamp = currentStamp - (currentDay - 1) * dayTime // 本周周一初时间戳（本周一的0点）
	console.log('本周周一：', new Date(MondayStamp))
	var SundayStamp = currentStamp + (8 - currentDay) * dayTime // 本周周日末时间戳（下周一的0点）
	console.log('下周周一：', new Date(SundayStamp))
	// 当传入的时间戳满足[本周一0点，下周一0点) ，说明传入的时间在本周内
	if (paramStamp >= MondayStamp && paramStamp < SundayStamp) {
		return true
	}
	return false
}

//将阿拉伯数字翻译成中文的大写数字
const numberToChinese = (num) => {
	var AA = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十");
	var BB = new Array("", "十", "百", "仟", "萬", "億", "点", "");
	var a = ("" + num).replace(/(^0*)/g, "").split("."),
		k = 0,
		re = "";
	for (var i = a[0].length - 1; i >= 0; i--) {
		switch (k) {
			case 0:
				re = BB[7] + re;
				break;
			case 4:
				if (!new RegExp("0{4}//d{" + (a[0].length - i - 1) + "}$")
					.test(a[0]))
					re = BB[4] + re;
				break;
			case 8:
				re = BB[5] + re;
				BB[7] = BB[5];
				k = 0;
				break;
		}
		//@ts-ignore
		if (k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0)
			re = AA[0] + re;
		//@ts-ignore
		if (a[0].charAt(i) != 0)
			//@ts-ignore
			re = AA[a[0].charAt(i)] + BB[k % 4] + re;
		k++;
	}
	if (a.length > 1) // 加上小数部分(如果有小数部分)
	{
		re += BB[6];
		for (var i = 0; i < a[1].length; i++)
			//@ts-ignore
			re += AA[a[1].charAt(i)];
	}
	if (re == '一十')
		re = "十";
	if (re.match(/^一/) && re.length == 3)
		re = re.replace("一", "");
	return re;
}

//将数字转换为大写金额
const changeToChinese = (Num) => {
	//判断如果传递进来的不是字符的话转换为字符
	if (typeof Num == "number") {
		Num = new String(Num);
	};
	Num = Num.replace(/,/g, "") //替换tomoney()中的“,”
	Num = Num.replace(/ /g, "") //替换tomoney()中的空格
	Num = Num.replace(/￥/g, "") //替换掉可能出现的￥字符
	if (isNaN(Num)) { //验证输入的字符是否为数字
		//alert("请检查小写金额是否正确");
		return "";
	};
	//字符处理完毕后开始转换，采用前后两部分分别转换
	var part = String(Num).split(".");
	var newchar = "";
	//小数点前进行转化
	for (var i = part[0].length - 1; i >= 0; i--) {
		if (part[0].length > 10) {
			return "";
			//若数量超过拾亿单位，提示
		}
		var tmpnewchar = ""
		var perchar = part[0].charAt(i);
		switch (perchar) {
			case "0":
				tmpnewchar = "零" + tmpnewchar;
				break;
			case "1":
				tmpnewchar = "壹" + tmpnewchar;
				break;
			case "2":
				tmpnewchar = "贰" + tmpnewchar;
				break;
			case "3":
				tmpnewchar = "叁" + tmpnewchar;
				break;
			case "4":
				tmpnewchar = "肆" + tmpnewchar;
				break;
			case "5":
				tmpnewchar = "伍" + tmpnewchar;
				break;
			case "6":
				tmpnewchar = "陆" + tmpnewchar;
				break;
			case "7":
				tmpnewchar = "柒" + tmpnewchar;
				break;
			case "8":
				tmpnewchar = "捌" + tmpnewchar;
				break;
			case "9":
				tmpnewchar = "玖" + tmpnewchar;
				break;
		}
		switch (part[0].length - i - 1) {
			case 0:
				tmpnewchar = tmpnewchar + "元";
				break;
			case 1:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
				break;
			case 2:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
				break;
			case 3:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
				break;
			case 4:
				tmpnewchar = tmpnewchar + "万";
				break;
			case 5:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
				break;
			case 6:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
				break;
			case 7:
				//@ts-ignore
				if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
				break;
			case 8:
				tmpnewchar = tmpnewchar + "亿";
				break;
			case 9:
				tmpnewchar = tmpnewchar + "拾";
				break;
		}
		var newchar = tmpnewchar + newchar;
	}
	//小数点之后进行转化
	if (Num.indexOf(".") != -1) {
		if (part[1].length > 2) {
			// alert("小数点之后只能保留两位,系统将自动截断");
			part[1] = part[1].substr(0, 2)
		}
		for (i = 0; i < part[1].length; i++) {
			tmpnewchar = ""
			perchar = part[1].charAt(i)
			switch (perchar) {
				case "0":
					tmpnewchar = "零" + tmpnewchar;
					break;
				case "1":
					tmpnewchar = "壹" + tmpnewchar;
					break;
				case "2":
					tmpnewchar = "贰" + tmpnewchar;
					break;
				case "3":
					tmpnewchar = "叁" + tmpnewchar;
					break;
				case "4":
					tmpnewchar = "肆" + tmpnewchar;
					break;
				case "5":
					tmpnewchar = "伍" + tmpnewchar;
					break;
				case "6":
					tmpnewchar = "陆" + tmpnewchar;
					break;
				case "7":
					tmpnewchar = "柒" + tmpnewchar;
					break;
				case "8":
					tmpnewchar = "捌" + tmpnewchar;
					break;
				case "9":
					tmpnewchar = "玖" + tmpnewchar;
					break;
			}
			if (i == 0) tmpnewchar = tmpnewchar + "角";
			if (i == 1) tmpnewchar = tmpnewchar + "分";
			newchar = newchar + tmpnewchar;
		}
	}
	//替换所有无用汉字
	while (newchar.search("零零") != -1)
		newchar = newchar.replace("零零", "零");
	newchar = newchar.replace("零亿", "亿");
	newchar = newchar.replace("亿万", "亿");
	newchar = newchar.replace("零万", "万");
	newchar = newchar.replace("零元", "元");
	newchar = newchar.replace("零角", "");
	newchar = newchar.replace("零分", "");
	if (newchar.charAt(newchar.length - 1) == "元") {
		newchar = newchar + "整"
	}
	return newchar;
}

export {
	toWei,
	fromWei,
	changeToChinese,
	numberToChinese,
	enumObjToArr,
	weekJudge,
	objectArraySortByAtr,
	chooseImage,
	arrObjGetArrByOneKey,
	arrObjremovalRepeat,
	arrObjGetEnum,
	doCopy,
	Toast,
	Jump,
	getAppVersion,
	chechVersion,
	fingerprint,
	isFingerprint,
	isNetwork,
	onNetwork,
	doScanCode,
	getUUID,
	imgToBase64,
	getCaption,
	getCaption1,
	getProvinces,
	getLocation,
	JumpUrl,
	urlIsOK,
	sleep,
	openURL,
	openNotice,
	guid,
	payJump,
	getConfig,
	removeProperty
}